<template>
  <div class= 'parent'>
      <el-popover placement="left" trigger="click">
        <template :loading="loading">
          <el-checkbox v-model="checked" @change="allChange">全选</el-checkbox><br />
          <el-checkbox v-model="checked0">订单编号</el-checkbox><br />
          <el-checkbox v-model="checked4">订单状态</el-checkbox><br />
          <el-checkbox v-model="checked6">专利名称</el-checkbox><br />
          <el-checkbox v-model="checked1">专利类型</el-checkbox><br />
          <el-checkbox v-model="checked3">申请号</el-checkbox><br />
          <el-checkbox v-model="checked2">专利权人</el-checkbox><br />
          <el-checkbox v-model="checked7">发明人</el-checkbox><br />
          <el-checkbox v-model="checked13">支付状态</el-checkbox><br />
          <el-checkbox v-model="checked20">缴费凭证</el-checkbox><br />
          <el-checkbox v-model="checked9">流程人员</el-checkbox><br />
          <el-checkbox v-model="checked10">代理人</el-checkbox><br />
          <el-checkbox v-model="checked5">提交时间</el-checkbox><br />
          <el-checkbox v-model="checked8">审查/补正文件</el-checkbox><br />
          <el-checkbox v-model="checked15">缴费通知书</el-checkbox><br />
          <el-checkbox v-model="checked12">答复文件</el-checkbox><br />
          <el-checkbox v-model="checked14">受理通知书</el-checkbox><br />
        </template>
        <el-button style="float: right;margin-bottom: 5px;margin-top: 0;" slot="reference" icon='el-icon-arrow-down'>显示字段</el-button>
      </el-popover>

    <span class="down-execel">
			<Poptip v-model="showFilter" placement="bottom-end" @on-popper-show ='getAllAgent'>
				<i class="el-icon-search poptip-condition-add"></i>
				<a href="javascript:;">列表查找</a>
				<div slot="content">
					<Poptip v-model="showFilterCondition" placement="bottom-start" class='poptip-condition'>
						<i class="el-icon-plus poptip-condition-add"></i>
						<a href="javascript:;" class='poptip-condition-add'>添加过滤条件</a>


						<div slot="content" class="condition-list">
							<ul>
								<li v-for="(item, index) in columns" :key="index" class = 'poptip-condition-item' @click="addFilterCondition(item)">{{item.label}}</li>
							</ul>
						</div>
					</Poptip>

					<el-form :model="conditionForm" ref="conditionForm" label-width="120px" class="demo-dynamic" @submit.native.prevent>
						<el-form-item
              v-for="(condition, index) in conditionForm.condition"
              :label="condition.label"
              :key="condition.key"
              :prop="'condition.' + index + '.value'"
              :rules="{ required: true, message: condition.label +'不能为空', trigger: 'blur' }">

              <el-select v-if='condition.label === "专利类型"' v-model="condition.value" placeholder="请选择专利类型" size="small">
                <el-option label="发明专利" value="F"></el-option>
                <el-option label="外观设计" value="W"></el-option>
                <el-option label="实用新型" value="S"></el-option>
              </el-select>
              <el-select v-else-if='condition.label === "支付状态"' v-model="condition.value" placeholder="请选择支付状态" size="small">
                <el-option label="已缴费" value="1"></el-option>
                <el-option label="未缴费" value="2"></el-option>
              </el-select>

              <el-select v-else-if='condition.label === "订单状态"' v-model="condition.value" placeholder="请选择订单状态" size="small">
								<el-option label="等待提交国知局" value="等待提交国知局"></el-option>
								<el-option label="已提交国知局" value="已提交国知局"></el-option>
								<el-option label="等待补正" value="等待补正"></el-option>
								<el-option label="已补正" value="已补正"></el-option>
								<el-option label="等待答复" value="等待答复"></el-option>
								<el-option label="已答复" value="已答复"></el-option>
								<el-option label="初步审查合格" value="初步审查合格"></el-option>
								<el-option label="实质审查中" value="实质审查中"></el-option>
								<el-option label="驳回" value="驳回"></el-option>
								<el-option label="授权" value="授权"></el-option>
								<el-option label="撤案" value="撤案"></el-option>
							</el-select>

              <el-date-picker
								v-model="submitTime"
								type="daterange"
								placeholder="选择日期"
								value-format="yyyy-MM-dd"
								size="small"
								:validate-event='false'
								@input = 'changInput'
								v-else-if='condition.label === "提交时间"'>
							</el-date-picker>

              <el-select
									size="small"
									filterable
									v-model="condition.value"
									v-else-if='condition.label === "流程人员"'>
									<el-option
										v-for="item in processOptions"
										:key="item.id"
										:label="$store.state.user.role_id == 2 ? item.email_work.split('@')[0].split('followup')[1] : item.name"
										:value="item.id">
									</el-option>
								</el-select>

							<el-input v-else size="small" v-model="condition.value" @keyup.enter.native="submitsearch('conditionForm')"></el-input>
							<el-button @click.stop="removeDomain(condition)" size="mini">删除</el-button>
						</el-form-item>
					</el-form>
					<div class= 'btns'>
						<el-button @click="submitsearch('conditionForm')" size="mini">查询</el-button>
						<el-button  @click.stop="resetForm('conditionForm')" size="mini">重置</el-button>
					</div>
				</div>
			</Poptip>
		</span>

    <el-table
      v-if="table_show"
      ref="parentTb"
      filters
      :data="tableData"
      border
      style="width: 100%;"
      height="87%"
      v-loading="loading"
      @sort-change='tableSortChange'
			@row-click='selectRow'>
      <el-table-column show-overflow-tooltip prop="id" label="ID" width="60" align="center">
				<template slot-scope="scope">
					{{(scope.$index+1)+(currentPage-1)*tableSize}}
				</template>
			</el-table-column>

      <el-table-column show-overflow-tooltip prop="order_number" v-if="checked0" label="订单编号" width="180" align="left" sortable='custom'>
				<template slot-scope="scope">
					<span>{{ scope.row.order_number }}</span>
				</template>
			</el-table-column>

      <el-table-column show-overflow-tooltip prop="status" label="订单状态" width="150" v-if="checked4" align="left" sortable='custom'>
				<template slot-scope="scope">
					<span>{{ scope.row.status }}</span>
				</template>
			</el-table-column>

      <el-table-column show-overflow-tooltip prop="name" label="专利名称" v-if="checked6" width="150" align="left" sortable='custom'>
				<template slot-scope="scope">
					<span>{{ scope.row.name }}</span>
				</template>
			</el-table-column>

      <el-table-column show-overflow-tooltip prop="type" label="专利类型" width="120" v-if="checked1" align="center" sortable='custom'>
				<template slot-scope="scope">
					<span v-if="scope.row.type == 'S'">实用新型</span>
					<span v-if="scope.row.type == 'W'">外观设计</span>
					<span v-if="scope.row.type == 'F'">发明专利</span>
				</template>
			</el-table-column>

      <el-table-column show-overflow-tooltip prop="application_number" label="申请号" v-if="checked3" width="150" align="left" sortable='left'>
				<template slot-scope="scope">
					<span>{{ scope.row.application_number }}</span>
				</template>
			</el-table-column>

      <el-table-column show-overflow-tooltip prop="patent_user" label="专利权人" v-if="checked2"  width="130" align="left" sortable='custom' >
				<template slot-scope="scope">
					<span v-if='scope.row.order'>{{ scope.row.order.patent_user }}</span>
				</template>
			</el-table-column>

      <el-table-column show-overflow-tooltip prop="user_name" label="发明人" v-if="checked7"  width="130" align="left" sortable='custom'>
				<template slot-scope="scope">
					<span v-if='scope.row.order'>{{ scope.row.order.user_name }}</span>
				</template>
			</el-table-column>

      <el-table-column show-overflow-tooltip v-if="checked13" prop="consumer_pay_status" label="支付状态" width="110" align="center" sortable='custom'>
        <template slot-scope="scope">
          <span
          v-if="scope.row.status != '撤案'"
            :class="(scope.row.consumer_pay_status == 1 || scope.row.consumer_pay_status == 0) ? 'finish' : (scope.row.consumer_pay_status == 2 ? 'unfinish' : 'orange')">
            {{ (scope.row.consumer_pay_status == 1 || scope.row.consumer_pay_status == 0) ? '已缴费' : (scope.row.consumer_pay_status == 2 ? '未缴费' : '已退款')  }}
          </span>
        </template>
			</el-table-column>
      <el-table-column
        label="缴费凭证"
        width="120"
        align="center"
        v-if="checked20"
        class-name="pay-status"
        sortable='custom'
        prop="consumer_pay_img">
        <template slot-scope="scope">
          <div @click.stop style="display: flex; align-item: center">
            <el-image
              v-if="scope.row.consumer_pay_img_thumb != null"
              :src="scope.row.consumer_pay_img_thumb"
              :preview-src-list="[scope.row.consumer_pay_img]"
            ></el-image>
          </div>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip v-if="checked9" prop="process" label="流程人员" width="120" align="center" sortable='custom'>
				<template slot-scope="scope">
					<!-- <div class="more">{{scope.row.process.name}}</div> -->
					<div class="more">
						<span style="margin-right: 10px" v-if="scope.row.order && scope.row.order.process"> {{ scope.row.order.process.email_work.split("@")[0].split("followup")[1] }} </span>
						<!-- <Tooltip  v-if="scope.row.order && scope.row.order.process"  content="点我留言">
							<i class="el-icon-chat-dot-round leaveWord" @click.stop="leaveWord(scope.row, 'process')"></i>
						</Tooltip> -->
					</div>
				</template>
			</el-table-column>

      <el-table-column show-overflow-tooltip prop="submit_at" label="提交时间" width="120" v-if="checked5"  align="center" sortable='custom'>
        <template slot-scope="scope">
          <span>{{ scope.row.submit_at }}</span>
        </template>
	    </el-table-column>

      <el-table-column v-if="checked8" prop="path" label="审查/补正文件" min-width="130" align="center">
        <template slot-scope="scope"  v-if="scope.row.opinion_file">
          <a v-for="item in scope.row.reviewFile"
            :key="item.id" :href="baseUrl + '/api/download?path='  + item.file +'/'+ item.path"
						:download="item.path" :title="item.path" class="el-icon-tickets downloadA"  @click.stop='stopPopup'></a>
        </template>
      </el-table-column>
      <el-table-column v-if="checked15" prop="path" label="缴费通知书" min-width="130" align="center">
        <template slot-scope="scope"  v-if="scope.row.demandNoteFile">
          <a v-for="item in scope.row.demandNoteFile"
            :key="item.id" :href="baseUrl + '/api/download?path='  + item.file +'/'+ item.path"
						:download="item.path" :title="item.path" class="el-icon-tickets downloadA"  @click.stop='stopPopup'></a>
        </template>
      </el-table-column>
      <el-table-column v-if="checked12" prop="path" label="答复文件" min-width="130" align="center">
        <template slot-scope="scope"  v-if="scope.row.answer_file">
          <a v-for="item in scope.row.answerFile"
            :key="item.id" :href="baseUrl + '/api/download?path='  + item.file +'/'+ item.path"
						:download="item.path" :title="item.path" class="el-icon-tickets downloadA" @click.stop='stopPopup'></a>
        </template>
      </el-table-column>

      <el-table-column prop='acceptance_note_fil' label="受理通知书" min-width="130" v-if="checked14"  align="center">
        <template slot-scope="scope">
          <i @click.stop="downloadAcceptance(scope.$index, scope.row.acceptance_note_fil)" v-if="scope.row.acceptance_note_file" class="el-icon-tickets downloadA">
            <a :id="'js_download' + scope.$index" :href="baseUrl+'/api/download?path='+scope.row.acceptance_note_file"  @click.stop='stopPopup'></a>
          </i>
        </template>
	    </el-table-column>
      <el-table-column
        width="200"
        v-if="checked99"
        align="center"
        label="操作"
        fixed="right">
        <template slot-scope="scope">
          <el-button
            v-no-more-click:3000
            @click.stop="upBill(scope.row)"
            type="primary"
            size="small"
            :disabled="(scope.row.status != '等待提交国知局' && scope.row.status != '已提交国知局' && scope.row.status == '撤案') || scope.row.consumer_pay_status != 2 || scope.row.consumer_pay_img != null">
            上传缴费凭证
          </el-button>
          <el-button
            v-no-more-click:3000
            @click.stop="upAnswer(scope.row)"
            type="primary"
            size="small"
            :disabled="scope.row.status != '等待答复' && scope.row.status != '等待补正'">
            {{ scope.row.status == '等待补正' ? '补正' : '答复' }}
          </el-button>
        </template>
      </el-table-column>
	  </el-table>

    <el-pagination class="pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
      :page-sizes="pageSizes" :page-size="Number(pageSize)" layout="total, sizes, prev, pager, next, jumper" :total="total">
    </el-pagination>

    <upload-fee ref="upload-fee" @refresh="refresh"></upload-fee>
    <answer-dialog ref="answer-dialog" @refresh="refresh"></answer-dialog>


    <!-- 查看订单 -->
    <lookOrder ref="lookOrder"/>
  </div>
</template>

<script>
import uploadFee from './components/upload-fee'
import answerDialog from './components/answer-dialog'
import lookOrder from './components/lookOrderDialog'
import { getMyInfo } from "~/api/user";
export default {
  components: {
    uploadFee,
    // promptMessage,
    lookOrder,
    answerDialog
  },
  data () {
    return {
      checked99: true,
      table_show: true,
      checked: true,
      checked0: true,
      checked1: true,
      checked2: true,
      checked3: true,
      checked4: true,
      checked5: true,
      checked6: true,
      checked7: true,
      checked8: true,
      checked9: true,
      checked10: true,
      checked12: true,
      checked13: true,
      checked14: true,
      checked15: true,
      checked20: true,
      tableData: [],
      loading: true,
      pageSizes: [25, 50],
      pageSize: 25,
      tableSize: 10, //一页几条
      tableStart: 0, //table数组过滤的第一条索引
      tableEnd: 10, //table数组过滤的最后一条索引
      currentPage: 1, //目前在第几页
      total: 0,
      showFilter: false, // 控制显示筛选条件
      showFilterCondition: false,
      baseUrl: global.baseurl,
			conditionForm: {
        condition: []
      }, //筛选条件
      columns: [
        {
          label: '订单编号',
          id: 1,
          parameter: 'order_number',
        },
        {
          label: '订单状态',
          id: 9,
          parameter: 'status'
        },
        {
          label: '专利类型',
          id: 3,
          parameter: 'type'
        },
        {
          label: '专利名称',
          id: 2,
          parameter: 'name'
        },
        {
          label: '申请号',
          id: 8,
          parameter: 'application_number'
        },
        {
          label: '专利权人',
          id: 4,
          parameter: 'patent_user'
        },
        {
          label: '发明人',
          id: 5,
          parameter: 'user_name'
        },
        {
          label: '流程人员',
          id: 6,
          parameter: 'process_id'
        },
        {
          label: '提交时间',
          id: 10,
          parameter: 'subimt_time'
        },
        {
          label: '支付状态',
          id: 11,
          parameter: 'consumer_pay_status'
        },

      ],
      submitTime: [],
      showRefund3: false,
      download_js: null,
      // stepsText: ['等待提交', '已提交国知局', '审查通过', '授权', '下证'],
      stepsText: ['等待提交', '已提交国知局', '审查通过', '授权'],
      opDateMax: 0,
      step_type: 'success',
      opData: [],
      showOP: true,
      paramsByPatent: {
        status: "等待提交国知局,已提交国知局,等待补正,已补正,等待答复,已答复,初步审查合格,实质审查中,驳回,授权,下证,撤案",
        sort_str: 'created_at',
        sort_order: 'desc'
        // page: 1
      },
      showRefund4: false,
      leaveWordText: '',
      leaveWordId: '',
      leaveWordEmail: '',
      leaveWordData: {},
      LorD: '',
      leaveWordLoading: false,
      processOptions: [],
      restaurants: {},
      restaurants2: [],
    }
  },

  computed: {
    selectArr() {
				let arr = [this.checked0, this.checked1, this.checked2, this.checked3, this.checked4, this.checked5, this.checked6, this.checked7, this.checked8, this.checked9, this.checked10, this.checked12, this.checked13, this.checked14, this.checked15, this.checked20]
				return arr
			}
  },
  watch: {
    tableData: {
      handler: function(val) {
        val.forEach(v => {
          if (v.consumer_pay_img) {
            v.consumer_pay_img = this.baseUrl + '/storage/upload/' + v.consumer_pay_img
          }
          if (v.consumer_pay_img_thumb) {
            v.consumer_pay_img_thumb = this.baseUrl + '/storage/upload/' + v.consumer_pay_img_thumb
          }
        })
      },
      immediate: true
    },
    selectArr(val) {
        this.table_show = false
        this.$nextTick(() => {
          this.table_show = true
        })
        setTimeout(() => {
          this.$nextTick(() => {
            this.gwm()
          })
        }, 300)
				if (val.some(v => v == false)) {
					this.checked = false
				} else {
					this.checked = true
        }
        if (val.every(v => v == false)) {
					this.checked99 = false
				} else {
					this.checked99 = true
				}
			},
  },
  mounted () {

  },
  created() {
    let that = this;
    that.$axios.get('api/consumer/patent', {
      params: this.paramsByPatent,
    })
    .then(res => {
      that.loading = false;
      that.tableData = res.data.data;
      that.pageSize = res.data.page.per_page;
      that.tableSize = res.data.page.per_page
      that.tableEnd = res.data.page.per_page;
      that.total = res.data.page.total
      for(let i = 0; i < that.tableData.length; i++) {
        that.files(that.tableData[i])
      }
    })

  },
  methods: {
    upAnswer(row) {
      this.$refs['answer-dialog'].showOn(row)
    },
    async getMyinfo () {
      let myInfo = await getMyInfo(this.$axios);
      if (myInfo.data.status == 'success') {
          this.$store.commit("setRoleInfo",myInfo.data.data)
          this.$store.commit("setUser",myInfo.data.data);
      }
    },
    gwm() {
				//水印,非管理员要设置
				if (this.$store.state.user.role_id != 1
					&& this.$route.path != '/admin/register'
					&& this.$route.path != '/admin/personalCenter/dstribution'
					&& this.$route.path != '/admin/personalCenter/myPurse'
					&& this.$route.path != '/admin/activityList/activityConfig'
					&& this.$route.path != '/admin/activityList/sysConfig'
					&& this.$route.path !='/admin/login'
					&& this.$route.path != '/admin/agentImprove'
					&& this.$route.path != '/order/login') {
					let that = this;
					let gwm = require('gwm');
					gwm.creation({
						'txt': that.$store.state.user.name,
						'container': '.el-table', //#gwm
						'fontSize': 40
					})
				}
			},
    allChange(val) {
				if (val) {
					this.checked0 = true;
					this.checked1 = true;
					this.checked2 = true;
					this.checked3 = true;
					this.checked4 = true;
					this.checked5 = true;
					this.checked6 = true;
					this.checked7 = true;
					this.checked8 = true;
          this.checked9 = true;
          this.checked10 = true;
          this.checked12 = true;
          this.checked13 = true;
          this.checked14 = true;
          this.checked15 = true;
          this.checked20 = true;
				} else {
					this.checked0 = false;
					this.checked1 = false;
					this.checked2 = false;
					this.checked3 = false;
					this.checked4 = false;
					this.checked5 = false;
					this.checked8 = false;
					this.checked7 = false;
					this.checked6 = false;
          this.checked9 = false;
          this.checked10 = false;
          this.checked12 = false;
          this.checked13 = false;
          this.checked14 = false;
          this.checked15 = false;
          this.checked20 = false;
				}
			},
    refresh() {
      this.getMyinfo()
      this.search1()
    },
    upBill(row) {
      this.$refs['upload-fee'].showOn(row)
    },
    //选择一页几条
    handleSizeChange(size) {
      this.paramsByPatent.perPage = size
      this.paramsByPatent.page = 1
      this.$axios.get('/api/consumer/patent',{
        params: this.paramsByPatent
        }
      )
      .then(res => {
        this.tableData = res.data.data;
        this.pageSize = res.data.page.per_page;
        this.tableSize = res.data.page.per_page;
        this.tableEnd = res.data.page.per_page;
        this.total = res.data.page.total;
      })
    },
    handleCurrentChange(val) {
      // this.currentPage = val;
      let that = this;
      let params = this.paramsByPatent
      this.paramsByPatent.page = val
      // let page = val;
      that.$axios.get('/api/consumer/patent?page=' + val,{
        params
      })
        .then(res => {
          that.loading = false;
          that.tableData = res.data.data;
          this.pageSize = res.data.page.per_page;
          this.tableSize = res.data.page.per_page;
          this.tableEnd = res.data.page.per_page;
          this.total = res.data.page.total;
        })
    },

    //获取所有代理人
    getAllAgent() {
      this.$axios.get('api/user/process')
        .then(res => {
          if (res.data.code == 200) {

            this.processOptions = res.data.data
          }
        })
        .catch(err => {
          this.$message({
            type: "err",
            message: err
          })
        })
    },

    addFilterCondition (item) {
      let filterItem = {
        value: '',
        label: item.label,
        parameter: item.parameter,
        key: Date.now()
      }
      if (this.conditionForm.condition.length > 0) {
        let conditionlabels = []
        for(let i = 0; i < this.conditionForm.condition.length; i++) {
          conditionlabels.push(this.conditionForm.condition[i].label)
        }
        let Check = conditionlabels.indexOf(item.label)
        Check == -1 ? this.conditionForm.condition.push(filterItem) : this.$message.error('请勿重复添加')
      } else {
        this.conditionForm.condition.push(filterItem)
      }

      this.showFilterCondition = false;
    },
		search1() {
      this.currentPage = 1
      for(var i = 0; i < this.conditionForm.condition.length; i++) {
        let a = this.conditionForm.condition[i].parameter
        this.paramsByPatent[a] = this.conditionForm.condition[i].value

        if (this.conditionForm.condition[i].parameter === 'subimt_time') {
          this.paramsByPatent.submit_start_time = this.submitTime[0]
          this.paramsByPatent.submit_end_time = this.submitTime[1]
        }
      }

      // 处理排序状态
      delete this.paramsByPatent.sort_str
      delete this.paramsByPatent.sort_order
      this.$refs['parentTb'].clearSort()

      //我的订单列表

      this.loading = true
      this.paramsByPatent.page = 1
      this.currentPage = 1
      console.log(this.paramsByPatent)
      this.$axios.get('api/consumer/patent', {
          params: this.paramsByPatent
      })
      .then(res => {
        this.loading = false;
        this.tableData = res.data.data;
        this.pageSize = res.data.page.per_page;
        this.tableSize = res.data.page.per_page;
        this.tableEnd = res.data.page.per_page;
        this.total = res.data.page.total;
        for(let i = 0; i < this.tableData.length; i++) {
          this.files(this.tableData[i])
        }
      })
    },
    files (data) {
      if (data.opinion_file == null || data.opinion_file == "") {}
      else {
        let fish_Arr = data.opinion_file.split("&");
        data.reviewFile = [];
        for (const i in fish_Arr) {
          let itemobj = {
            id: i + 1,
            path: fish_Arr[i],
            file: ''
          };
          let itemArr = itemobj.path.split("/")
          itemobj.path = itemArr[itemArr.length - 1]
          itemobj.file = itemArr.slice(0, 2).join("/");
          data.reviewFile.push(itemobj);
        }
      }
      if (data.answer_file == null || data.answer_file == "") {}
      else {
        let fish_Arr = data.answer_file.split("&");
        data.answerFile = [];
        for (const i in fish_Arr) {
          let itemobj = {
            id: i + 1,
            path: fish_Arr[i],
            file: ''
          };
          let itemArr = itemobj.path.split("/")
          itemobj.path = itemArr[itemArr.length - 1]
          itemobj.file = itemArr.slice(0, 2).join("/");
          data.answerFile.push(itemobj);
        }
      }
      if (data.order) {
        if (data.order.img == null || data.order.img == "") {}
        else {
          let fish_Arr = data.order.img.split("&");
          data.order.imgArr = [];
          for (const i in fish_Arr) {
            let itemobj = {
              id: i + 1,
              path: fish_Arr[i],
              file: ''
            };
            let itemArr = itemobj.path.split("/")
            itemobj.path = itemArr[itemArr.length - 1]
            itemobj.file = itemArr.slice(0, 2).join("/");
            data.order.imgArr.push(itemobj);
          }
        }
        if (data.order.file == null || data.order.file == "") {}
        else {
          let fish_Arr = data.order.file.split("&");
          data.order.fileArr = [];
          for (const i in fish_Arr) {
            let itemobj = {
              id: i + 1,
              path: fish_Arr[i],
              file: ''
            };
            let itemArr = itemobj.path.split("/")
            itemobj.path = itemArr[itemArr.length - 1]
            itemobj.file = itemArr.slice(0, 2).join("/");
            data.order.fileArr.push(itemobj);
          }
        }
      }
      if (data.demand_note_file == null || data.demand_note_file == "") {

      } else {
        let fish_Arr = data.demand_note_file.split("&");
        data.demandNoteFile = [];
        for (const i in fish_Arr) {
          let itemobj = {
            id: i + 1,
            path: fish_Arr[i],
            file: ''
          };
          let itemArr = itemobj.path.split("/")
          itemobj.path = itemArr[itemArr.length - 1]
          itemobj.file = itemArr.slice(0, 2).join("/");
          data.demandNoteFile.push(itemobj);
        }
      }

    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.$refs['parentTb'].clearSort()
      this.conditionForm.condition.forEach(v => {
        if (v.value) {
          v.value = null
        }
      });
      this.submitTime = []
      this.paramsByPatent = {
        status: "等待提交国知局,已提交国知局,等待补正,已补正,等待答复,已答复,初步审查合格,实质审查中,驳回,授权,下证,撤案",
        sort_str: 'status',
        sort_order: 'desc'
      }
      this.$nextTick(() => {
        this.$refs[formName].clearValidate()
      })
      // this.search1()
      // this.showFilterCondition = false
      // this.showFilter = false
    },

    submitsearch(formName) {
      let that = this
      this.$refs[formName].validate((valid, prop) => {
      // this.$refs[formName].clearValidate();
        let props = []
        for (let k in prop) {
          props.push(prop[k][0].field)
          if (prop[k][0].message = '提交时间不能为空') {
            if (that.submitTime) {
              if (that.submitTime.length > 0) {
                that.$refs[formName].clearValidate([prop[k][0].field])
                // that.search()
                let timeIndex = props.indexOf('提交时间不能为空')
                props.splice(timeIndex, 1)
              }
            } else {
              return false
            }
          }
        }
        if (props.length) {
          that.$refs[formName].validateField(props, (valid2) => {
            if(valid2) {
              return false;
            } else {
              that.search1()
              this.showFilter = false
            }
          })
        } else {
          that.search1()
          this.showFilter = false
        }
      })
    },
    removeDomain(item) {
      this.showFilter = true
      delete this.paramsByPatent[item.parameter]
      let index = this.conditionForm.condition.indexOf(item)
      if (index !== -1) {
        this.conditionForm.condition.splice(index, 1)
      }

      if (item.label === '提交时间') {
        this.submitTime = []
        delete this.paramsByPatent.submit_start_time
				delete this.paramsByPatent.submit_end_time
      }
      this.search1()
    },
    openLook (item) {},
    selectRow (row) {
      if(window.getSelection().toString() === ''){
        // this.$refs.lookOrder.show(row)
      }
    },
    downloadAcceptance (index, row) {
      this.download_js = `js_download${index}`
      document.getElementById(this.download_js).click()
    },
    tableSortChange(column) {
      if (column.order === 'descending') {
        this.paramsByPatent.sort_str = column.prop
        this.paramsByPatent.sort_order = 'desc'
      } else if (column.order === 'ascending') {
        this.paramsByPatent.sort_str = column.prop
        this.paramsByPatent.sort_order = 'asc'
      } else {
        delete this.paramsByPatent.sort_str
        delete this.paramsByPatent.sort_order
      }
      // if (column.prop == 'order' || column.prop == 'user_name') {
      //   return
      // }
      this.loading = true
      this.$axios.get('api/consumer/patent', {
          params: this.paramsByPatent
      })
        .then(res => {
          this.loading = false
          this.tableData = res.data.data
          this.pageSize = res.data.page.per_page
          this.tableSize = res.data.page.per_page
          this.tableEnd = res.data.page.per_page
          this.total = res.data.page.total

          for(let i = 0; i < this.tableData.length; i++) {
            this.files(this.tableData[i])
          }

        })
    },
    changInput () {
      this.$refs['conditionForm'].clearValidate();
    },
    leaveWord (row, role) {
      this.showRefund4 = true;
      this.showRefund3 = false;
      this.leaveWordId = row.order.id
      if (role == 'process') {
        this.LorD = '流程人员'
        // this.leaveWordEmail = row.process.email_work
      }
      this.leaveWordData = row
    },
    submitLeaveWord () {
      let that = this
      // this.leaveWordEmail = row.agent.email_work
      let submitLeaveWordOrder = {
        message: that.leaveWordText,
        id: this.leaveWordId
      }
      let url = ''
      let agentName = ' '
      let isProcess = true
      if(this.leaveWordData.order.agent) {
        agentName= this.leaveWordData.order.agent.name
      }

      if(this.LorD === '流程人员') {
        url = `api/consumer/${that.leaveWordId}/process/message`

      } else {
        url = `api/consumer/${that.leaveWordId}/message`
        isProcess = false
      }
      // this.leaveWordLoading = false
      that.$axios.post(url, submitLeaveWordOrder)
      .then(({ data }) => {
        if (data.code == 200) {
          this.showRefund4 = false;

          if(isProcess) {
            let pData = {
              userName: this.$store.state.user.name,
              email:this.leaveWordData.order.process.email_work,
              phone:this.leaveWordData.order.process.phone,
              number:this.leaveWordData.order.process.email_work.split("@")[0].split("followup")[1]
            }
            this.$refs['promptMessage'].showDialog('processLeaveWord',pData)
          } else {
            let pData = {
              userName: this.$store.state.user.name,
              email:this.leaveWordData.order.agent.email_work,
              phone:this.leaveWordData.order.agent.phone,
              number:this.leaveWordData.order.agent.email_work.split("@")[0].slice(-3)
            }
            this.$refs['promptMessage'].showDialog('agentLeaveWord',pData)
          }

        } else {
          this.$message.error(data.message);
        }
      })
      this.LorD = ''
    },
    leaveWordClose () {
      this.leaveWordText = ''
      this.submitLeaveWordOrder = null
    },
    stopPopup () {

    }
  }
}
</script>

<style lang='less' type='text/css'>


  .parent{
    height: 100%;
  }

  .el-main .poptip-condition .ivu-poptip-popper .ivu-poptip-content .ivu-poptip-inner {
		min-width: 180px;
	}
  .el-main .ivu-poptip .ivu-poptip-popper .ivu-poptip-content .ivu-poptip-inner{
    min-width: 480px ;
    // height: 300px;
    overflow-y:scroll;
  }

	.down-execel {
		display: block;
		height: 40px;
		line-height: 40px;
		color: #333333;
		font-size: 14px;
		float: right;
		margin-right: 20px;
  }

	.poptip-condition {
		display: block;
		margin-top: 10px;
		.poptip-condition-item {
			line-height: 25px;
			cursor:pointer;
		}
		.poptip-condition-add {
			font-size: 14px;
		}
	}
	.demo-dynamic {
		padding-left: 10px;
		.el-form-item {
			margin-bottom: 12px;
		}
		.el-input {
			width: 240px;
		}
		.el-date-editor {
			width: 240px;
		}
		.el-button {
			padding: 9px 15px;
			vertical-align: baseline;
		}
		.el-form-item__error {
			padding-top: 0 ;
		}

	}

	.el-main .poptip-condition .ivu-poptip-popper .ivu-poptip-content .ivu-poptip-inner {
		min-width: 180px;
  }
  .el-pagination {
    margin-top: 30px;
  }
	.btns {
		margin-top: 10px;
  }
  .downloadA{
    color: #2d8cf0;
    font-size: 26px;
    margin-right: 5px;
  }

  .steps {
    margin-left: 20px;
  }
  .el-steps {
    margin-top: 20px;
    .el-step__head{
      &.is-wait{
        .el-step__icon {
          &.is-text{
            .el-step__icon-inner{
              display: none; //不要序号
            }
          }
        }
      }
    }
    .el-step__main{
      // min-width: 110px;
      width: 100%;
      .el-step__title {
        text-align: center;
        font-size: 15px;
        width: 100%;
        line-height: 20px;
      }
    }
  }
  .parentLookOrder {
    overflow-y:scroll;

    // .el-steps {

    // }
  }
  .leaveWordDialog {
    .el-dialog {
      width: 35%;
    }
    .leaveWord-label {
      display: block;
      margin-bottom: 10px;
    }
    .el-textarea {
      display: block;
      margin-bottom: 20px;
    }
  }
  .leaveWord {
    color: rgb(16, 133, 16);
    font-size: 18px;

  }
  .el-table {
    .el-table__body {
      .pay-status {
        padding: 0;
        .cell {
          display: flex;
          align-items: center;
          justify-content: center;
          .el-image {
            width: 25px;
            height: 25px;
            margin-left: 10px;
            &:nth-last-child(1) {
              margin-left: 0;
            }
            image {
              width: 100%;
              height: 100%;
              display: block;
            }
          }
        }
      }
    }
  }

</style>
